<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ page import="com.liuya.db.sql.xml.DefineVariable" %>
<%@ page import="com.liuya.safe.policy.handler.AbstractPolicyDesignHandler" %>
<%@ page import="com.liuya.db.sql.xml.Formula" %>
<%@ page import="com.liuya.db.sql.xml.ExprGroupTypeItem" %>
<%@ page import="com.liuya.db.sql.xml.BinaryExpr" %>
<%@ page import="com.liuya.common.I18N" %>

<%
    I18N i18n = I18N.getInstance();

    String nodeId = request.getParameter("nodeId");
    String pId = request.getParameter("pId");

    ExprGroupTypeItem item = (ExprGroupTypeItem) request.getAttribute("item");
    BinaryExpr expr = null;
    String nullType = "";
    String varName = "";

    if (item != null) {
        if (item.getIsNotNullExpr() != null) {
            varName = item.getIsNotNullExpr().getVariable().getName();
            nullType = "NOT NULL";
        } else if (item.getIsNullExpr() != null) {
            varName = item.getIsNullExpr().getVariable().getName();
            nullType = "NULL";
        }
    }

    AbstractPolicyDesignHandler handler = (AbstractPolicyDesignHandler) request.getAttribute("handler");
    DefineVariable[] variables = handler.getVariables();
%>

<% if (nodeId != null) { %>
<input type="hidden" name="nodeId" value="<%=nodeId %>"/>
<input type="hidden" name="oper" value="editExpr"/>
<% } %>
<% if (pId != null) { %>
<input type="hidden" name="pId" value="<%=pId %>"/>
<input type="hidden" name="oper" value="addExprChild"/>
<% } %>
<input type="hidden" name="exprType" value="null"/>

<label><%=i18n.say("Variable")%>
</label>
<select name="varName">
    <% for (int i = 0; i < variables.length; i++) {
        String tempName = variables[i].getName();
        boolean selected = tempName.equals(varName);
    %>
    <option value="<%=tempName%>" <%=selected ? "selected" : "" %>><%=tempName %>
    </option>
    <% } %>
</select>
<br/>

<label><%=i18n.say("Operator")%>
</label>
<select name="operator">
    <option value="NULL" <%=nullType.equals("NULL") ? "selected" : "" %>>NULL</option>
    <option value="NOT NULL" <%=nullType.equals("NOT NULL") ? "selected" : "" %>>NOT NULL</option>
</select>